from django.db import models


class SystemPermission(models.Model):
	path = models.CharField(max_length=100, verbose_name='跳转地址')
	route_name = models.CharField(max_length=50, verbose_name='路径名')
	title = models.CharField(max_length=50, verbose_name='菜单名称')
	url = models.CharField(max_length=100, verbose_name='接口地址')
	parent_id = models.IntegerField(verbose_name='上级ID')
	sort = models.IntegerField(default=0, verbose_name='排序')
	type = models.CharField(max_length=2, verbose_name='惨淡类型(D目录 M菜单 B按钮)')
	status = models.BooleanField(default=1, verbose_name='状态')
	deleted = models.BooleanField(default=0)
	create_time = models.DateTimeField(auto_now_add=True)
	update_time = models.DateTimeField(auto_now=True)

	class Meta:
		db_table = 'tiresias_sys_permission'
		verbose_name = '系统权限'
		verbose_name_plural = verbose_name

	def __str__(self):
		return f'{self.route_name}: {self.path}'


class SystemRole(models.Model):
	name = models.CharField(max_length=50, verbose_name='角色名')
	status = models.BooleanField(default=1, verbose_name='状态')
	mark = models.CharField(max_length=100, verbose_name='备注')
	deleted = models.BooleanField(default=0)
	create_time = models.DateTimeField(auto_now_add=True)
	update_time = models.DateTimeField(auto_now=True)

	class Meta:
		db_table = 'tiresias_sys_role'
		verbose_name = '角色表'
		verbose_name_plural = verbose_name


class SystemRolePermission(models.Model):
	role_id = models.IntegerField(verbose_name='角色ID')
	permission = models.ForeignKey(SystemPermission, on_delete=models.DO_NOTHING, related_name='permission', verbose_name='权限ID')
	create_time = models.DateTimeField(auto_now_add=True)

	class Meta:
		db_table = 'tiresias_sys_role_permission'
		verbose_name = '角色权限关联表'
		verbose_name_plural = verbose_name

	def __str__(self):
		return self.permission.url
